package game_logic;

import game_logic.control.GameController;
import game_logic.control.MoveController;
import game_logic.control.listener.AcceptThread;
import game_logic.control.listener.Listener;
import game_logic.model.Board;
import game_logic.view.BoardView;
import game_logic.view.SimpleBoardView;
import connect.Client;

/**
 * 游戏工厂，外界通过这个类构造游戏
 */
public interface GameFactory {
    /**
     * 构造游戏
     *
     * @param tarIP    对方的 IP 地址
     * @param redBelow 将红方放在界面下面
     * @param redFirst 红方先手
     * @return 游戏控制器
     */
    static Controller makeGame(String tarIP, boolean redBelow, boolean redFirst, Client client, int owner) {
        Listener listener = new Listener(redBelow, client, owner);
        BoardView boardView = new SimpleBoardView(listener, redBelow);
        Board board = new Board();
        GameController gameController = new GameController(board, new MoveController(), boardView, redFirst);
        listener.bind(gameController, tarIP, board);
        if (client != null) {
            AcceptThread accept_thread = new AcceptThread(listener, gameController,board);
            accept_thread.start();
        }
        return gameController;
    }
}
